import CommonBaseSchema from '#common/base_schema'

export default class extends CommonBaseSchema {
  protected tableName = 'service_rights'

  async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments()

      table.integer('fk_shop_id').notNullable().unsigned().references('shops.id').comment('店铺ID')

      table.integer('fk_goods_id').notNullable().unsigned().references('goods.id').comment('商品ID')

      table.string('name', 100).comment('名称')
      table.integer('times').unsigned().defaultTo(0).comment('次数')
      table.integer('gift_times').unsigned().defaultTo(0).comment('赠送次数')
      table.integer('normal_price').unsigned().defaultTo(0).comment('普通价格')
      table.integer('sale_price').unsigned().defaultTo(0).comment('销售价格')
      table.integer('exp_num').unsigned().comment('权益数量')
      table.integer('exp_type').unsigned().comment('权益类型 1购买时 2消费时')
      table.enum('exp_unit', ['year', 'month', 'day']).comment('权益单位')
      table.tinyint('status').unsigned().defaultTo(1).comment('状态')
      table.string('memo', 255).defaultTo('').comment('备注')

      this.defineCommonColumns(table)
      table.comment('服务权益表')
    })
  }

  async down() {
    this.schema.dropTable(this.tableName)
  }
}
